label: Position the text properly
authorBenjamin Otte <otte@redhat.com>
Wed, 16 Dec 2015 19:39:51 +0000 (20:39 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 16 Dec 2015 19:39:51 +0000 (20:39 +0100)
The PangoLayout needs to be positioned according to the content
allocation of the gadget, not the widget's allocation.

gtk/gtkcssgadget.c
gtk/gtkcssgadgetprivate.h
gtk/gtklabel.c

index ac355c553399bb06bea297a9b7f054035aca251a..895855779d3c47f70641a1b90aea72c4c4f3f729 100644 (file)
@@ -698,3 +698,38 @@ gtk_css_gadget_get_border_allocation (GtkCssGadget  *gadget,
     }
 }
 
+void
+gtk_css_gadget_get_content_allocation (GtkCssGadget  *gadget,
+                                       GtkAllocation *allocation,
+                                       int           *baseline)
+{
+  GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
+  GtkBorder margin, border, padding, extents;
+  GtkCssStyle *style;
+
+  g_return_if_fail (GTK_IS_CSS_GADGET (gadget));
+
+  style = gtk_css_gadget_get_style (gadget);
+  get_box_margin (style, &margin);
+  get_box_border (style, &border);
+  get_box_padding (style, &padding);
+  extents.top = margin.top + border.top + padding.top;
+  extents.right = margin.right + border.right + padding.right;
+  extents.bottom = margin.bottom + border.bottom + padding.bottom;
+  extents.left = margin.left + border.left + padding.left;
+
+  if (allocation)
+    {
+      allocation->x = priv->allocated_size.x + extents.left;
+      allocation->y = priv->allocated_size.y + extents.top;
+      allocation->width = priv->allocated_size.width - extents.left - extents.right;
+      allocation->height = priv->allocated_size.height - extents.top - extents.bottom;
+    }
+  if (baseline)
+    {
+      if (priv->allocated_baseline >= 0)
+        *baseline = priv->allocated_baseline - extents.top;
+      else
+        *baseline = -1;
+    }
+}
index 9d4b6e40ca608867daa726b025bb27812f2a3863..551064fde6a330c4480d0dd1b10d17fc16dbee0d 100644 (file)
@@ -100,6 +100,9 @@ void            gtk_css_gadget_draw                     (GtkCssGadget
 void            gtk_css_gadget_get_border_allocation    (GtkCssGadget           *gadget,
                                                          GtkAllocation          *allocation,
                                                          int                    *baseline);
+void            gtk_css_gadget_get_content_allocation   (GtkCssGadget           *gadget,
+                                                         GtkAllocation          *allocation,
+                                                         int                    *baseline);
 
 G_END_DECLS
 
index bcbd3410fbf831baa1268526778d1ab2287c41c0..e87139aa40edb2c8c5d748968232fae56dc7231f 100644 (file)
@@ -3403,16 +3403,18 @@ gtk_label_update_layout_width (GtkLabel *label)
 
   if (priv->ellipsize || priv->wrap)
     {
+      GtkAllocation allocation;
       GtkBorder border;
       PangoRectangle logical;
       gint width, height;
 
+      gtk_css_gadget_get_content_allocation (priv->gadget, &allocation, NULL);
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
       _gtk_misc_get_padding_and_border (GTK_MISC (label), &border);
 G_GNUC_END_IGNORE_DEPRECATIONS
 
-      width = gtk_widget_get_allocated_width (GTK_WIDGET (label)) - border.left - border.right;
-      height = gtk_widget_get_allocated_height (GTK_WIDGET (label)) - border.top - border.bottom;
+      width = allocation.width - border.left - border.right;
+      height = allocation.height - border.top - border.bottom;
 
       if (priv->have_transform)
         {
@@ -4011,12 +4013,13 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   req_width  += border.left + border.right;
   req_height += border.top + border.bottom;
 
-  gtk_widget_get_allocation (widget, &allocation);
+  gtk_css_gadget_get_content_allocation (priv->gadget,
+                                         &allocation,
+                                         &baseline);
 
   x = floor (allocation.x + border.left + xalign * (allocation.width - req_width) - logical.x);
 
   baseline_offset = 0;
-  baseline = gtk_widget_get_allocated_baseline (widget);
   if (baseline != -1 && !priv->have_transform)
     {
       layout_baseline = pango_layout_get_baseline (priv->layout) / PANGO_SCALE;